const autoprefixer = require('autoprefixer');
const pxtorem = require('postcss-pxtorem');

const pkg = require('./package.json')
const CompressionWebpackPlugin = require('compression-webpack-plugin')
process.env.VUE_APP_NAME = process.env.VUE_APP_NAME || pkg.appName

// eslint-disable-next-line no-unused-vars
const ENV = process.env.NODE_ENV || 'development'
console.log(" 当前环境",ENV)
// eslint-disable-next-line no-unused-vars
let HOST = 'http://localhost:81'

module.exports = {
    outputDir: '../vote',
    // publicPath: process.env.NODE_ENV === 'production' ? '/public/vote/' : '/',
    publicPath: '/',
    css: {
        loaderOptions: {
            postcss: {
                plugins: [
                    autoprefixer(),
                    pxtorem({
                        rootValue: 16,
                        propList: ['*']
                    })
                ]
            }
        }
    },
    configureWebpack: config => {
        if (ENV === 'production') {
            config.plugins.push(new CompressionWebpackPlugin({
                algorithm: 'gzip',
                test: /\.(js|css|html)$/,
                threshold: 10240,
                minRatio: 0.8
            }))
            // config.externals = {
            //   'vue': 'Vue',
            //   'vue-router': 'VueRouter',
            //   'axios': 'axios'
            // }
        }
    },
    productionSourceMap: false,
    devServer: {
        proxy: HOST
    },
    chainWebpack: config => {
        config.module
            .rule('vue')
            .use('vue-loader')
            .loader('vue-loader')
            .tap(options => {
                // 修改它的选项...
                return options
            })
    }

};
